/*     */ package com.newcrm.webapi.sub;
/*     */ 
/*     */ import com.newcrm.bean.CustomerSearchCondition;
/*     */ import com.newcrm.bean.User;
/*     */ import com.newcrm.db.CustomerManager;
/*     */ import com.newcrm.exception.NotFoundException;
/*     */ import com.newcrm.util.Util;
/*     */ import com.newcrm.webapi.AbstractAction;
/*     */ import com.newcrm.webapi.AbstractHttpServlet;
/*     */ import java.io.IOException;
/*     */ import java.io.PrintWriter;
/*     */ import javax.servlet.ServletException;
/*     */ import javax.servlet.http.HttpServletRequest;
/*     */ import javax.servlet.http.HttpServletResponse;
/*     */ import net.sf.json.JSONObject;
/*     */ 
/*     */ public class AddCustomerShare extends AbstractAction
/*     */ {
/*     */   public AddCustomerShare(AbstractHttpServlet servlet)
/*     */   {
/*  24 */     super(servlet);
/*     */   }
/*     */ 
/*     */   public void parse(HttpServletRequest request, HttpServletResponse response)
/*     */     throws IOException, ServletException, NotFoundException
/*     */   {
/*  30 */     User loginUser = getLoginUser(request);
/*  31 */     String userId = loginUser.userId;
/*  32 */     response.setContentType("text/html;charset=utf-8");
/*  33 */     PrintWriter out = response.getWriter();
/*  34 */     JSONObject jsonObject = new JSONObject();
/*     */ 
/*  36 */     String customerIds = Util.getURLParameter(request
/*  37 */       .getParameter("CustomerIds"));
/*     */ 
/*  39 */     String shareUserIds = Util.getURLParameter(request
/*  40 */       .getParameter("ShareUserIds"));
/*  41 */     String shareGroupIds = Util.getURLParameter(request
/*  42 */       .getParameter("ShareGroupIds"));
/*  43 */     String selectAll = Util.getURLParameter(request
/*  44 */       .getParameter("selectAll"));
/*     */ 
/*  46 */     if (((shareUserIds == null) || (shareUserIds.trim().length() == 0)) && (
/*  47 */       (shareGroupIds == null) || (shareGroupIds.trim().length() == 0))) {
/*  48 */       jsonObject.put("error", "0");
/*  49 */       jsonObject.put("addShareNum", Integer.valueOf(0));
/*  50 */       out.println(jsonObject);
/*  51 */       out.flush();
/*  52 */       out.close();
/*  53 */       return;
/*     */     }
/*     */ 
/*  57 */     if ("1".equals(selectAll)) {
/*  58 */       CustomerSearchCondition searchCondition = new CustomerSearchCondition(
/*  59 */         request, loginUser, false);
/*     */ 
/*  61 */       CustomerManager manager = new CustomerManager();
/*  62 */       String[] arrayShareUserIds = shareUserIds.split(",");
/*  63 */       String[] arrayShareGroupIds = shareGroupIds.split(",");
/*     */ 
/*  65 */       int resultForUser = 0;
/*  66 */       int resultForGroup = 0;
/*  67 */       for (int i = 0; i < arrayShareUserIds.length; i++) {
/*  68 */         resultForUser = manager.addShareSelectAll(searchCondition, 
/*  69 */           arrayShareUserIds[i], loginUser, 1);
/*     */       }
/*  71 */       for (int i = 0; i < arrayShareGroupIds.length; i++) {
/*  72 */         resultForGroup = manager.addShareSelectAll(searchCondition, 
/*  73 */           arrayShareGroupIds[i], loginUser, 
/*  74 */           2);
/*     */       }
/*     */ 
/*  77 */       jsonObject.put("error", "0");
/*  78 */       jsonObject.put("addShareNum", Integer.valueOf(resultForUser + resultForGroup));
/*  79 */       out.println(jsonObject);
/*  80 */       out.flush();
/*  81 */       out.close();
/*  82 */       return;
/*     */     }
/*     */ 
/*  86 */     if ((customerIds == null) || (customerIds.trim().length() == 0)) {
/*  87 */       jsonObject.put("error", "1");
/*  88 */       out.println(jsonObject);
/*  89 */       out.flush();
/*  90 */       out.close();
/*  91 */       return;
/*     */     }
/*     */ 
/*  94 */     CustomerManager manager = new CustomerManager();
/*  95 */     int num = manager.addShare(customerIds, userId, shareUserIds, 
/*  96 */       shareGroupIds);
/*  97 */     jsonObject.put("error", "0");
/*  98 */     jsonObject.put("addShareNum", Integer.valueOf(num));
/*  99 */     out.println(jsonObject);
/* 100 */     out.flush();
/* 101 */     out.close();
/*     */   }
/*     */ }

/* Location:           C:\E\referenceProject\CRM参考\qikebao\WEB-INF\lib\qikebao.jar
 * Qualified Name:     com.newcrm.webapi.sub.AddCustomerShare
 * JD-Core Version:    0.6.1
 */